package com.aceitunaproject.server.terrain;

/**
 * Represents the effects of a given combination of equipment,terrain or other
 * factors in the movement capabilities of an unit (time unit cost of entering
 * terrain, whether or not the unit can enter the tile (not a "movement effect"
 * per se, but useful), perhaps also time unit reloading rate)
 * 
 * @author Federico Bergstein
 * 
 */
public class MovementEffects {

	// The cost in time units for an unit to enter a MapTile
	private int timeUnitCost;

	// wheter or not the unit can enter a map tile
	private boolean canEnterTile;

	/**
	 * 
	 * @return The cost in time units for an unit to enter a MapTile
	 */
	public int getTimeUnitCost() {
		return timeUnitCost;
	}

	/**
	 * 
	 * @return wheter or not the unit can enter a map tile
	 */
	public boolean canEnterTile() {
		return canEnterTile;
	}

	public MovementEffects() {

	}

	public MovementEffects(int timeUnitCost, boolean canEnterTile) {

		this.canEnterTile = canEnterTile;
		this.timeUnitCost = timeUnitCost;
	}

	// Adds two combat effect sets and returns the combination of the 2
	public static MovementEffects add(MovementEffects movementEffectsA,
			MovementEffects movementEffectsB) {

		MovementEffects result = new MovementEffects();
		result.timeUnitCost = movementEffectsA.timeUnitCost
				+ movementEffectsB.timeUnitCost;
		result.canEnterTile = movementEffectsA.canEnterTile
				&& movementEffectsB.canEnterTile;
		return result;
	}

	@Override
	public boolean equals(Object anObject) {
		if (!super.equals(anObject)) {
			if (anObject instanceof MovementEffects) {

				MovementEffects comparisonObject = (MovementEffects) anObject;

				return (this.timeUnitCost == comparisonObject.timeUnitCost && this.canEnterTile == comparisonObject.canEnterTile);

			} else {
				return false;
			}
		} else {
			return true;
		}

	}

}
